package com.example.demo.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.example.demo.entity.Sysuser;
import com.example.demo.mapper.DataMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.jws.WebParam;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/login") //每一个控制都要有名称
public class LoginController {
    //自己添加的
    @Resource
    private DataMapper dataMapper; //自己

    @RequestMapping("/")
    public String login(Model model){

        model.addAttribute("username","ceshiyonghuming");

        return "login";
        //return "check_xiao";
    }



    @RequestMapping("/logindo")
    @ResponseBody
    public Object logindo(@RequestParam String username,
                          @RequestParam String password){
        //打印语句
        System.out.println("username="+username+";password="+password);
        //定义条件构造器
        EntityWrapper con = new EntityWrapper<Sysuser>();
        con.eq("username",username);
        con.eq("password",password);

        List<Sysuser> res = dataMapper.selectMaps(con);

        return res;
    }

    @RequestMapping("/logindo2")
    @ResponseBody
    public String logindo2(@RequestParam String username,
                           @RequestParam String password){

        System.out.println("username="+username+";password="+password);

        EntityWrapper con=new EntityWrapper<Sysuser>();
        con.eq("username",username);
        con.eq("password",password);

        List<Sysuser> res=dataMapper.selectMaps(con);

        if(res.isEmpty()){
            System.out.println("fail");
            return "fail";
        }
        else{
            return "success";
        }

    }


}
